<?php

namespace App\Models;

use App\Models\Concerns\ProductTraits;


/**
 * Class Blog
 * @property integer id
 * @property string title 标题
 * @property string sub_title 副标题
 * @property string content 内容
 * @property string cover 封面图
 * @property string cover_list 列表封面图
 * @property string cover_detail 详情封面图
 * @property boolean status 发布状态
 * @property integer view_count 浏览量
 * @property integer sort 排序
 * @property date start_time 显示开始时间
 * @property date end_time 显示结束时间
 */
class Topic extends ApplicationModel
{
    use ProductTraits;
    protected $fillable = [
        'title',
        'sub_title',
        'content',
        'cover',
        'cover_detail',
        'cover_list',
        'status',
        'view_count',
        'sort',
        'start_time',
        'end_time',
        'share_title',
        'share_subtitle',
        'share_url',
        'share_content',
        'share_head',
        'discount_picture',
        'first_discount_flag'
    ];

    public function scopeRelease($query)
    {
        //return $query->where('status', true)->where('start_time', '<=', date('Y-m-d H:i:s'))->where('end_time', '>=', date('Y-m-d H:i:s'));
        return $query->where('start_time', '<=', date('Y-m-d H:i:s'))->where('end_time', '>=', date('Y-m-d H:i:s'));
    }

    public function share_content()
    {
        $do_main = config('constants.DO_MAIN');
        $share_url = 'http://www.superxing.cc/topic/index.html?imgurl='.$this->share_url.'&title='.$this->share_title;
        $arr = array(
            'qqShare' => array('title' => $this->share_title, 'content' => $this->share_subtitle, 'url' => $share_url, 'cover' => $this->cover_detail),
            'wxShare' => array('title' => $this->share_title, 'content' => $this->share_subtitle, 'url' => $share_url, 'cover' => $this->cover_detail),
            'wxQuan' => array('title' => $this->share_title, 'content' => $this->share_subtitle, 'url' => $share_url, 'cover' => $this->cover_detail),
            'wbShare' => array('title' => $this->share_title, 'content' => $this->share_subtitle, 'url' => $share_url, 'cover' => $this->cover_detail),
            'qqZone' => array('title' => $this->share_title, 'content' => $this->share_subtiel, 'url' => $share_url, 'cover' => $this->cover_detail),
        );

        return $arr;
    }
}
